package com.disruptor.sample._06multi.producer;

import com.disruptor.sample.common.dto.LongEvent;
import com.lmax.disruptor.RingBuffer;

public class LongEventProducerByMulti {

  private final RingBuffer<LongEvent> ringBuffer;

  public LongEventProducerByMulti(RingBuffer<LongEvent> ringBuffer) {
    this.ringBuffer = ringBuffer;
  }

  public void onData(long value) {
    long sequence = ringBuffer.next();
    try {
      LongEvent event = ringBuffer.get(sequence);
      event.setValue(value);
    } finally {
      ringBuffer.publish(sequence);
    }
  }

}
